package guimy;

import static net.mindview.util.SwingConsole.run;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.TimeUnit;

//: gui/LongRunningTask.java
// A badly designed program.
import javax.swing.JButton;
import javax.swing.JFrame;

public class LongRunningTask extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3130459415061906616L;
	private JButton b1 = new JButton("Start Long Running Task"), b2 = new JButton("End Long Running Task");

	public LongRunningTask() {
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				try {
					TimeUnit.SECONDS.sleep(3);
				} catch (InterruptedException e) {
					System.out.println("Task interrupted");
					return;
				}
				System.out.println("Task completed");
			}
		});
		b2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				// Interrupt yourself?
				Thread.currentThread().interrupt();
			}
		});
		setLayout(new FlowLayout());
		add(b1);
		add(b2);
	}

	public static void main(String[] args) {
		run(new LongRunningTask(), 200, 150);
	}
} /// :~
